#include "Dynamic_Dialog.h"
#include "xVMRelationStruct.h"
#include <vector>
#include "DlgEntry.h"

const int DEFAULT_BUTTON_SPACE = 80;

extern HINSTANCE _hInst ;  // this instance is defined in DIVA_MAIN
extern HWND _hWnd ;        // this instance is defined in DIVA_Application

int x, y, width, height;
vector<DlgEntry*> entrys; 
int button_space = DEFAULT_BUTTON_SPACE;

BOOL CALLBACK DynDlgProc(HWND, UINT, WPARAM, LPARAM);


void Dynamic_Dialog::setButtonSpace(int button_height){
	button_space = button_height;
}

void Dynamic_Dialog::showDialog(){
	/*TODO: change to Qt dialog*/
	//DialogBox( _hInst, "DYN_DLG", _hWnd, (DLGPROC)DynDlgProc);
}

void Dynamic_Dialog::setWindowPos(int x_in, int y_in, int width_in, int height_in){
	x = x_in;
	y = y_in;
	width = width_in;
	height = height_in;
}

void Dynamic_Dialog::addEntry(LPCSTR unitType, LPCSTR default_val, string valueType,
							  int id, DWORD style, int x, int y, int width, int height){
								  DlgEntry* entry = new DlgEntry();

								  entry->default_val = default_val;
								  entry->id = id;
								  entry->type = unitType;
								  entry->x = x;
								  entry->y = y;
								  entry->width = width;
								  entry->height = height;
								  entry->valueType = valueType;
								  entry->style = style;;

								  entrys.push_back(entry);
}

void Dynamic_Dialog::clear(){
	entrys.clear();
}

string Dynamic_Dialog::getValue(int id){
	vector<DlgEntry*>::iterator itor;
	for(itor = entrys.begin();itor!=entrys.end();itor++){
		DlgEntry* entry = (*itor);
		if(entry->id == id){
			return entry->value;
		}
	}
	assert(false);

	return "";
}

string Dynamic_Dialog::getValue(string paraName){
	vector<DlgEntry*>::iterator itor;
	bool bfound = false;

	for(itor = entrys.begin();itor!=entrys.end();itor++){
		DlgEntry* entry = (*itor);
		if(bfound == true){
			int id = entry->id;
			return getValue(id);
		}
		if(entry->default_val == paraName){
			bfound = true;
		}
	}
	assert(false);

	return "";
}